package org.lep.leetcode.datastructure.stack.queueusingstack;

import java.util.Stack;

/**
 * https://leetcode-cn.com/problems/implement-queue-using-stacks
 *
 * @author lverpeng
 * @since 2020/3/10
 */
public class MyQueue1 {
    private Stack<Integer> stackIn;
    private Stack<Integer> stackOut;

    /**
     * Initialize your data structure here.
     */
    public MyQueue1() {
        stackIn = new Stack<>();
        stackOut = new Stack<>();
    }

    /**
     * Push element x to the back of queue.
     */
    public void push(int x) {
        while (!stackIn.empty()) {
            stackOut.push(stackIn.pop());
        }
        stackIn.push(x);
        while (!stackOut.empty()) {
            stackIn.push(stackOut.pop());
        }
    }

    /**
     * Removes the element from in front of queue and returns that element.
     */
    public int pop() {
        return stackIn.pop();
    }

    /**
     * Get the front element.
     */
    public int peek() {
        return stackIn.peek();
    }

    /**
     * Returns whether the queue is empty.
     */
    public boolean empty() {
        return stackIn.isEmpty();
    }

    public static void main(String[] args) {
        int x = 10;
        int x1 = 11;
        int x2 = 12;
        MyQueue1 obj = new MyQueue1();
        obj.push(x);
        obj.push(x1);
        obj.push(x2);
        int param_3 = obj.peek();
        int param_2 = obj.pop();
        int param_5 = obj.pop();
        int param_6 = obj.pop();
        boolean param_4 = obj.empty();

        System.out.println(param_3);
        System.out.println(param_2);
        System.out.println(param_5);
        System.out.println(param_6);
        System.out.println(param_4);
    }
}
